home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-02-25 | 2.8 KB | 115 lines | [TEXT/MPS ] |
- /*********************************************************************
- Project : GUSI - Grand Unified Socket Interface
- File : GUSIRemoteConsole.cp - Divert standard I/O to other
- application.
- Author : Matthias Neeracher
- Language : MPW C++
-
- $Log: GUSIRemoteConsole.cp,v $
- Revision 1.1 1994/02/25 02:30:15 neeri
- Initial revision
-
- *********************************************************************/
-
- #pragma force_active on
-
- #include "GUSIPPC_P.h"
-
- #include <SysEqu.h>
- #include <Script.h>
- #include <TextUtils.h>
- #include <PLStringFuncs.h>
-
- class GUSIRemoteConsoleDomain : public DeviceSocketDomain {
- static Socket * console;
- public:
- GUSIRemoteConsoleDomain() : DeviceSocketDomain(AF_REMOTECON) { }
-
- virtual Socket * open(const char * filename, int oflag);
- };
-
- GUSIRemoteConsoleDomain GUSIRemoteConsoleSockets;
-
- Socket * GUSIRemoteConsoleDomain::console = (Socket *) nil;
-
- static sa_constr_ppc RemoteConConstr = {
- PPC_CON_NEWSTYLE+PPC_CON_MATCH_TYPE,
- "\p",
- {
- smRoman,
- "\p",
- ppcByString,
- "\pRemote Console"
- }
- };
-
- Socket * GUSIRemoteConsoleDomain::open(const char * filename, int flags)
- {
- char title[256];
-
- strncpy(title, filename, 7);
- title[7] = 0;
-
- if (equalstring(title, (char *) "stdin", false, true)) {
- flags = O_RDONLY;
-
- if (filename[5])
- return (Socket *) TryNextDevice;
- else
- filename += 5;
- } else if (equalstring(title, (char *) "stdout", false, true)) {
- flags = O_WRONLY;
-
- if (filename[6])
- return (Socket *) TryNextDevice;
- else
- filename += 6;
- } else if (equalstring(title, (char *) "console", false, true)) {
- if (filename[7])
- return (Socket *) TryNextDevice;
- else
- filename += 7;
- } else
- return (Socket *) TryNextDevice;
-
- if (!console) {
- if (!(console = PPCSockets.socket(SOCK_STREAM, 0)))
- goto lose;
-
- sockaddr_ppc addr;
- int len = sizeof(sockaddr_ppc);
-
- addr.family = AF_PPC;
- addr.port.nameScript = smRoman;
- addr.port.portKindSelector = ppcByString;
- addr.location.locationKindSelector = ppcNBPTypeLocation;
-
- PLstrcpy(addr.port.name, (StringPtr) CurApName);
- PLstrcpy(addr.location.u.nbpType, "\pPPCToolBox");
- PLstrcpy(addr.port.u.portTypeStr, "\pRemote Console Client");
-
- if (console->bind((struct sockaddr *) &addr, sizeof(sockaddr_ppc))) {
- if (errno != EADDRINUSE)
- goto lose;
-
- strcpy((char *) addr.port.name+addr.port.name[0]+1, " - 2");
- addr.port.name[0] += 4;
-
- while (console->bind((struct sockaddr *) &addr, sizeof(sockaddr_ppc))) {
- if (errno != EADDRINUSE || addr.port.name[addr.port.name[0]] == '9')
- goto lose;
- ++addr.port.name[addr.port.name[0]];
- }
- }
- if (PPCSockets.choose(0, "Please choose a console to connect to", &RemoteConConstr, 0, &addr, &len))
- goto lose;
- if (console->connect(&addr, len))
- goto lose;
- }
-
- return console;
-
- lose:
- exit(1);
- }
-